import { Ref, inject, onMounted, onUnmounted } from "vue"
import { MainDetailModalKey } from '@/types/keys'
import type { RefFunType } from '@/types/interface'

const useMainModal = ()=>{
    let isMainDetailModal : Ref
    const changeMainModal = ()=>{
        isMainDetailModal.value = !isMainDetailModal.value
    }

    const getMainModal : RefFunType<Boolean> = () : Ref<Boolean> =>{
        return inject(MainDetailModalKey)!
    }

    onMounted(()=>{
        isMainDetailModal = getMainModal()
    })

    onUnmounted(()=>{
        isMainDetailModal.value = false
    })

    return { changeMainModal,getMainModal }
}

export default useMainModal